/**
 * 
 */
package com.ynet.middleground.riskmanage.service.impl;

import java.util.List;

import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.bean.*;
import com.ynet.middleground.riskmanage.dto.*;
import com.ynet.middleground.riskmanage.model.DaGangModel;
import com.ynet.middleground.riskmanage.service.DaGangService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @ClassName DaGangServiceImpl
 * @Description 对接大港服务实现类
 * @Author songyf
 * @Date 2020/8/18 10:50
 * @Version 1.0
 */

@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Api(value = "对接大港服务实现类", tags = {"对接大港服务实现类"})
@Path("dagang")
@Service(timeout = 6000, version = "0.0.1")
public class DaGangServiceImpl implements DaGangService, GenericService {
    @Autowired
    DaGangModel daGangModel;

    /**
     * @author songyf
     * @Description 货种信息查询
     * @Date 2020-08-18 14:36
     * @Param MasterGoodsTypeQueryReqPager
     * @return MasterGoodsTypeDTO
     **/
    @POST
    @Path("goods-type")
    @ApiOperation(value = "货种信息查询", notes = "货种信息查询")
    @ApiImplicitParam(name = "requestObj", dataType = "MasterGoodsTypeQueryReqPager", paramType = "body",
        required = true)
    @Override
    public ServiceResult<List<MasterGoodsTypeDTO>> getMasterGoodsType(@Valid MasterGoodsTypeQueryReqPager req) {
        ServiceResult<List<MasterGoodsTypeDTO>> result = new ServiceResult<>();
        try {
            result.setResult(daGangModel.getMasterGoodsType(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "货种信息查询服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(req.getPagerInfo());
        return result;
    }

    /**
     * @author songyf
     * @Description 船期信息查询
     * @Date 2020-08-19 14:36
     * @Param DgShipCycleQueryReq
     * @return DgShipCycleDTO
     **/
    @POST
    @Path("ship_cycle")
    @ApiOperation(value = "船期信息查询", notes = "船期信息查询")
    @ApiImplicitParam(name = "requestObj", dataType = "DgShipCycleQueryReq", paramType = "body", required = true)
    @Override
    public ServiceResult<List<DgShipCycleDTO>> getShipCycle(@Valid DgShipCycleQueryReq req) {
        ServiceResult<List<DgShipCycleDTO>> result = new ServiceResult<>();
        try {
            result.setResult(daGangModel.getShipCycle(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "船期信息查询服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }

    /* *//**
          * @author songyf
          * @Description 海关放行信息查询
          * @Date 2020-08-19 17:36
          * @Param DgShipCycleQueryReq
          * @return DgShipCycleDTO
          **//*
             @POST
             @Path("customs-release")
             @ApiOperation(value = "海关放行信息查询", notes = "海关放行信息查询")
             @ApiImplicitParam(name = "requestObj", dataType = "DgCustomsReleaseReq", paramType = "body", required = true)
             @Override
             //public ServiceResult<List<DgCustomsReleaseDTO>> getCustomsRelease(@Valid DgCustomsReleaseReq req) {
             public ServiceResult<List<RzgCustomsReleaseDTO>> getCustomsRelease(@Valid DgCustomsReleaseReq req) {
             ServiceResult<List<RzgCustomsReleaseDTO>> result = new ServiceResult<>();
             try {
                 result.setResult(daGangModel.getCustomsRelease(req));
             } catch (BusinessException be) {
                 result.setError(be.getCode(), be.getMessage());
             } catch (Exception e) {
                 IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "海关放行信息查询服务异常, case: {}",
                         Throwables.getStackTraceAsString(e));
                 result.setError("ECRM0000", "服务异常，请联系系统管理员");
             }
             return result;
             }*/

    /**
     * @author songyf
     * @Description 港存信息查询
     * @Date 2020-08-19 20:36
     * @Param DgYardCargoQueryReq
     * @return DgYardCargoDTO
     **/
    @POST
    @Path("yard-cargo")
    @ApiOperation(value = "港存信息查询", notes = "港存信息查询")
    @ApiImplicitParam(name = "requestObj", dataType = "DgYardCargoQueryReq", paramType = "body", required = true)
    @Override
    public ServiceResult<DgYardCargoDTO> getYardCargo(@Valid DgYardCargoQueryReq req) {
        ServiceResult<DgYardCargoDTO> result = new ServiceResult<>();
        try {
            result.setResult(daGangModel.getYardCargoDTO(req));
            result.setPagerInfo(req.getPagerInfo());
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "港存信息查询服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }

    /**
     * @author songyf
     * @Description 历史业务量信息查询
     * @Date 2020-08-20 10:36
     * @Param DgCargoInYardQueryReq
     * @return DgCargoInYardDTO
     **/
    @POST
    @Path("yard-cargo-history")
    @ApiOperation(value = "历史业务量信息查询", notes = "历史业务量信息查询")
    @ApiImplicitParam(name = "requestObj", dataType = "DgCargoInYardQueryReq", paramType = "body", required = true)
    @Override
    public ServiceResult<List<DgCargoInYardDTO>> getCargoInYard(@Valid DgCargoInYardQueryReq req) {
        ServiceResult<List<DgCargoInYardDTO>> result = new ServiceResult<>();
        try {
            result.setResult(daGangModel.getCargoInYard(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "历史业务量信息查询服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }

    /**
     * @author songyf
     * @Description 质押监管情况查询
     * @Date 2020-08-20 15:00
     * @Param DgCargoControlQueryReq
     * @return DgCargoControlDTO
     **/
    @POST
    @Path("cargo-control")
    @ApiOperation(value = "质押监管情况查询", notes = "质押监管情况查询")
    @ApiImplicitParam(name = "requestObj", dataType = "DgCargoControlQueryReq", paramType = "body", required = true)
    @Override
    public ServiceResult<DgCargoControlDTO> getCargoControl(@Valid DgCargoControlQueryReq req) {
        ServiceResult<DgCargoControlDTO> result = new ServiceResult<>();
        try {
            result.setResult(daGangModel.getCargoControl(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "质押监管情况查询服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }
}
